<template>
  <section class="responsive-quick-nav">
    <div class="quick-nav-grid" :class="gridClass">
      <div
        v-for="nav in quickNavs"
        :key="nav.path"
        class="quick-nav-item"
        @click="handleNavClick(nav.path)"
      >
        <div class="nav-icon" :style="{ backgroundColor: nav.color || '#ff6b35' }">
          <el-icon><component :is="nav.icon" /></el-icon>
        </div>
        <span class="nav-text">{{ nav.name }}</span>
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useResponsive } from '@/utils/responsive'

interface QuickNav {
  name: string
  path: string
  icon: string
  color?: string
}

interface Props {
  quickNavs: QuickNav[]
}

const props = defineProps<Props>()
const router = useRouter()
const { isMobile, isTablet, isDesktop, screenWidth } = useResponsive()

// 根据屏幕尺寸计算网格类名
const gridClass = computed(() => {
  if (isMobile.value) {
    if (screenWidth.value <= 480) {
      return 'quick-nav-grid--xs'
    }
    return 'quick-nav-grid--sm'
  } else if (isTablet.value) {
    return 'quick-nav-grid--md'
  } else {
    return 'quick-nav-grid--lg'
  }
})

// 处理导航点击
const handleNavClick = (path: string) => {
  router.push(path)
}
</script>

<style scoped>
.responsive-quick-nav {
  margin-bottom: 30px;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.quick-nav-grid {
  display: grid;
  gap: 20px;
  /* 确保网格居中 */
  justify-content: center;
  /* 设置最大宽度，避免在大屏幕上过于分散 */
  max-width: 800px;
  margin: 0 auto;
}

/* 小屏幕手机 (≤480px) */
.quick-nav-grid--xs {
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: none;
}

/* 大屏幕手机/小平板 (≤768px) */
.quick-nav-grid--sm {
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  max-width: none;
}

/* 平板 (≤1024px) */
.quick-nav-grid--md {
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 16px;
  max-width: 600px;
}

/* 桌面端 (>1024px) */
.quick-nav-grid--lg {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 24px;
  max-width: 900px;
}

.quick-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 15px 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
  /* 确保每个项目的最小宽度 */
  min-width: 100px;

  &:hover {
    background: #fff5f0;
    transform: translateY(-2px);
  }

  &:active {
    transform: translateY(0);
  }
}

.nav-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  color: white;
  font-size: 24px;
  transition: all 0.3s ease;
}

.nav-text {
  font-size: 14px;
  color: #333;
  text-align: center;
  font-weight: 500;
  /* 确保文字不会换行 */
  white-space: nowrap;
  
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 响应式断点样式 */
@media (max-width: 480px) {
  .quick-nav-item {
    min-width: auto;
    padding: 10px 6px;
    
    .nav-icon {
      width: 36px;
      height: 36px;
      font-size: 18px;
    }
    
    .nav-text {
      font-size: 11px;
    }
  }
}

@media (max-width: 768px) {
  .quick-nav-item {
    min-width: auto;
    padding: 12px 8px;
    
    .nav-icon {
      width: 40px;
      height: 40px;
      font-size: 20px;
    }
    
    .nav-text {
      font-size: 12px;
    }
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .quick-nav-item {
    .nav-icon {
      min-width: 44px;
      min-height: 44px;
    }
  }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
  .responsive-quick-nav {
    padding: 15px;
  }
  
  .quick-nav-grid {
    gap: 15px;
  }
  
  .quick-nav-item {
    padding: 10px 8px;
  }
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .nav-icon {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  .responsive-quick-nav {
    background: #1a1a1a;
    color: #ffffff;
  }
  
  .quick-nav-item {
    &:hover {
      background: #2a2a2a;
    }
  }
  
  .nav-text {
    color: #cccccc;
  }
}

/* 减少动画（用户偏好） */
@media (prefers-reduced-motion: reduce) {
  .quick-nav-item,
  .nav-icon {
    transition: none;
  }
  
  .quick-nav-item:hover {
    transform: none;
  }
}
</style>
